import 'package:flutter/material.dart';
import 'package:flutter_scaffold/flutter_scaffold.dart';

class ListenerDemoPage extends StatefulWidget {
  @override
  State createState() {
    return _ListenerDemoPageState();
  }
}

class _ListenerDemoPageState extends State<ListenerDemoPage> {
  PointerEvent? _event;

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("listener 使用")),
      body: Listener(
        behavior: HitTestBehavior.deferToChild,
        child: InkWell(
          onTap: () {
            Fluttertoast.showToast(msg: "dfdfjd");
          },
          child: Container(
            width: double.infinity,
            height: double.infinity,
            child: Text("触摸坐标:"+_event.toString()),
          ),
        ),
        onPointerMove: (event) {
          setState(() {
            _event = event;
          });
        },
        onPointerUp: (event) {
          setState(() {
            _event = event;
          });
        },
        onPointerDown: (event) {
          setState(() {
            _event = event;
          });
        },
        onPointerCancel: (event) {
          setState(() {
            _event = event;
          });
        },
      ),
    );
  }
}
